package com.sicheng.lc.周赛.分类.哈西表or计数or滑动窗口or双指针.滑动窗口;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/14 10:27
 */
public class 统计得分严格小于k的子数组数目 {
    //https://leetcode.cn/problems/count-subarrays-with-score-less-than-k/
    public long countSubarrays(int[] nums, long k) {

        int l = 0;
        long preSum = 0;
        long res = 0;
        for (int r = 0; r < nums.length; r++) {
            preSum += nums[r];

            while (preSum * (r - l + 1) >= k) {
                preSum -= nums[l];
                l++;
            }
            res += r - l + 1;

        }
        return res;
    }


}
